<section id="content">
  <div class="block">
    <header>
      <h2>Přidat fotografie</h2>
    </header>
    <!-- HTML5 sekce pro reference -->
    <section class="block-body">
      <?php if (!isset($dataPost)): ?>
      <script type="text/javascript">
        var pole = new Array();
        var i = 0;
        $(function() {
          $('#file-upload').uploadify({
            'uploader'       : '/media/js/uploadify/uploadify.swf',
            'script'         : '/files/uploadify/',
            'folder'         : '/temp',
            'cancelImg'      : '/media/js/uploadify/cancel.png',
            'multi'          : true,
            'auto'           : false,
            'fileExt'        : '*.jpg',
            'fileDesc'       : 'Image Files (.jpg)',
            'simUploadLimit' : 1,
            'removeCompleted': false,
            'queueID'        : 'custom-queue',
            'buttonImg'   : '/media/js/uploadify/button_cz.gif',
            'height' : 32,
            'width' : 139,
            'scriptData': {'session': '<?php echo Session::instance()->id(); ?>'},
            'onError'     : function (event,ID,fileObj,errorObj) {
              $('#status-message').text(errorObj.type + ' Error: ' + errorObj.info);
            },
            'onSelectOnce'   : function(event,data) {
              $('#status-message').text('Fotografií ve frontě: ' + data.filesSelected);
              $('a#uploadify-upload').css('visibility','visible');
            },
            'onComplete'  : function(event, queueID, fileObj, response, data) {
              var errorOccured = response.substring(0,5).toUpperCase() == "ERROR:";
              if (errorOccured) {
                $("#status-message").html(response.substring(6,response.length));
                return false;
              } else {
                $('#photo-images').insertPhoto(fileObj.filePath);
                pole[i] = [fileObj.name];
                i++;
              }
            },
            'onAllComplete'  : function(event, data) {
              if(data.errors == 0) {
                $('#status-message').text('Úspěšně nahraných fotografií: '+ data.filesUploaded);
                $('#uploadify-controls').text('');
                $('#photo-upload').fadeIn();
                $('#src').val(pole);
              }
            }
          });
        });
      </script>
      <div id="uploadify">
        <div id="status-message">Kliknutím vyberte fotografie pro přidání.</div>
        <div id="custom-queue"></div>
        <div id="uploadify-controls">
          <input id="file-upload" type="file" name="Filedata" />
          <a id="uploadify-upload" class="submit" href="javascript:$('#file-upload').uploadifyUpload()">Nahrát soubory</a>
        </div>
      </div>      
      <div class="clear-both"></div>
      <?php endif ?>
      <div id="photo-upload" <?php if (!isset($dataPost)) { echo 'class="hide"'; } ?>>
        <?php
        if (!isset($dataPost)) {
          $dataPost = array('title' => '', 'description' => '', 'tags' => array(), 'src' => '');
        }
        ?>
        <form action="<?php echo url::base(); ?>files/upload" method="post" id="form">
          <fieldset>
            <ul>
              <li>
                <label for="title">Název fotografií:</label>
                <input type="text" id="title" name="title" value="<?php echo $dataPost['title'] ?>" class="text" />
              </li>
              <li>
                <label for="description">Popis:</label>
                <textarea cols="10" rows="10" name="description" class="text" ><?php echo $dataPost['description'] ?></textarea>
              </li>
              <li>
              <label for="tags">Tagy:</label>
              <div id="container-tags">
                <input id="tags" type="text" name="tags" value="" class="text" />
                <span class="top-right2"><a href="javascript:;" id="tag-add" class="button-dark" title="">+</a></span>
              </div>
              <div id="dialog-confirm">
                <p>Skutečně chcete tento tag odtranit?</p>
              </div>
              <?php $i = 123456; foreach ($dataPost['tags'] as $item): ?>
                <label class="text-tags" id="tag<?php echo $i; ?>">
                  <input type="hidden" value="<?php echo $item->tag; ?>" name="tags[]" readonly="readonly"><?php echo $item->tag; ?>
                  <a title="Odstranit" class="href-gray" onclick="tagDelete(<?php echo $i; ?>,<?php echo $item->id; ?>)" href="javascript:;">(x)</a>
                </label>
              <?php $i++; endforeach ?>
            </li>
              <li>
                <label for="user_profile_allowed">Umístit pouze na profil:</label>        <input type="checkbox" id="user_profile_allowed" name="user_profile_allowed" value="1" />
              </li>
              <li>
                <label for="user_comments_allowed">Povolit komentáře:</label>        <input type="checkbox" id="user_comments_allowed" name="user_comments_allowed" value="1" checked="checked" />
              </li>
              <li>
              <input type="submit" name="form-submit" value="odeslat"  />
              </li>
              <li>
                <input type="hidden" id="src" name="src" value="<?php echo $dataPost['src'] ?>" class="text" />
              </li>
            </ul>
          </fieldset>
        </form>
      </div>
      <div id="photo-images"></div>
    </section>
  </div>
  <div class="block-bottom"></div>
</section>
<script>
  $(function() {
    $( "#dialog-confirm" ).hide();
  });

  function tagDelete(number,id) {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      width: 400,
      minHeight: 40,
      modal: true,
      draggable: false,
      closeOnEscape: true,
      open: function(event, ui) { $(".ui-dialog-titlebar-close,.ui-dialog-titlebar").remove(); },
      buttons: {
        "Odstranit": function() {          
          $('#tag'+number+'').remove();
          $( this ).dialog( "close" );
        },
        "Zavřít": function() {
          $( this ).dialog( "close" );
        }
      }
    });
  }
</script>

